package services

import (
	"ais-go/app/models"
	"github.com/xuri/excelize/v2"
)

func Test() {
	//initGangkou()
	//return
	//var gangkouList []models.Gangkou
	//var gangkouList1 []models.Gangkou
	////models.Db.Find(&gangkouList)
	////查找前50条数据
	//models.Db.Find(&gangkouList)
	//for _, gangkou := range gangkouList {
	//	coutry := gangkou.Country
	//	if strings.Contains(coutry, "(") {
	//		str := strings.Split(coutry, "(")
	//		str = strings.Split(str[1], ")")
	//		str1 := tools.StrToLower(str[0])
	//		var gangkou1 models.Gangkou
	//		gangkou1.Country = gangkou.Country
	//		gangkou1.PortId = gangkou.PortId
	//		gangkou1.PortCn = gangkou.PortCn
	//		gangkou1.PortName = gangkou.PortName
	//		gangkou1.CountryCn = gangkou.CountryCn
	//		gangkou1.UnLoCode = gangkou.UnLoCode
	//		gangkou1.Lat = gangkou.Lat
	//		gangkou1.Lon = gangkou.Lon
	//		gangkou1.Icon = str1
	//		gangkou1.Id = gangkou.Id
	//		gangkouList1 = append(gangkouList1, gangkou1)
	//		if len(gangkouList1) == 1000 {
	//			models.Db.Save(&gangkouList1)
	//			gangkouList1 = []models.Gangkou{}
	//		}
	//	}
	//}
	////fmt.Println(gangkouList1)
	//models.Db.Save(&gangkouList1)
}

func initGangkou() {
	var gangkouList []models.Gangkou
	file, _ := excelize.OpenFile("C:\\Users\\chun\\Desktop\\port.xlsx")
	rows, _ := file.GetRows("Sheet1")
	for _, row := range rows {
		var gangkou models.Gangkou
		gangkou.Country = row[2]
		gangkou.PortId = row[3]
		gangkou.PortCn = row[4]
		gangkou.PortName = row[7]
		gangkou.CountryCn = row[6]
		gangkou.UnLoCode = row[8]
		gangkou.Lat = row[10]
		gangkou.Lon = row[9]
		gangkouList = append(gangkouList, gangkou)
		if len(gangkouList) == 1000 {
			models.Db.Create(&gangkouList)
			gangkouList = []models.Gangkou{}
		}
	}
	models.Db.Create(&gangkouList)
}
